#!/bin/bash
set -e

while getopts  ":s:p:" opts
do
	case  $opts  in
	s)
	sample_name=$OPTARG
	;;
	p)
	out_prefix=$OPTARG
	;;
	\?)
	echo `basename $0` '[-p out_prefix] reads1.fq[.gz] reads2.fq[.gz]'
	exit 1
	;;
	esac
done
shift $(($OPTIND - 1))

if [ -z "$2" ]; then
	echo `basename $0` '[-p out_prefix] reads1.fq[.gz] reads2.fq[.gz]'
	exit 1
fi


#-----------------------------------------------
#-----------------------------------------------
. /mnt/ilustre/app/medical/tools/.var #---------
#-----------------------------------------------

echo out prefix name is: $out_prefix 2>>$log 1>&2



# truseq_uni=AATGATACGGCGACCACCGAGATCTACACTCTTTCCCTACACGACGCTCTTCCGATCT

# truseq_uni_res_com=AGATCGGAAGAGCGTCGTGTAGGGAAAGAGTGTAGATCTCGGTGGTCGCCGTATCATT

# truseq_uni_res_com_22=AGATCGGAAGAGCGTCGTGTAG
truseq_uni_res_com_20=AGATCGGAAGAGCGTCGTGT

# truseq_0=GATCGGAAGAGCACACGTCTGAACTCCAGTCAC
# truseq_1=ATCTCGTATGCCGTCTTCTGCTTG

# truseq1=${truseq_0}${barcode}${truseq_1}

# truseq_0_22=GATCGGAAGAGCACACGTCTGA
# truseq_0_20=GATCGGAAGAGCACACGTCT
truseq_0_20=AGATCGGAAGAGCACACGTC

tem_seq1=TGGAATTCTCGGGTGCCAAG

tem_seq2=AGATCGGAAGAGCGTCGT

# primer5=$data_path/ref/b37/lunca50/primer5N.fa
# primer3=$data_path/ref/b37/lunca50/primer3N.fa



# $cutadapt \
# -n 2 \
# -q 10 \
# --trimmed-only \
# -m 65 \
# -M 200 \
# -a $truseq_0_20 \
# -A $truseq_uni_res_com_20 \
# -o $s1.cut.fastq \
# -p $s2.cut.fastq \
# $1 \
# $2 \
# 2>>$log 1>&2

# $cutadapt \
# -n 2 \
# -q 10 \
# -m 65 \
# -M 200 \
# -a $truseq_0_20 \
# -A $truseq_uni_res_com_20 \
# -o $s1.cut.fastq \
# -p $s2.cut.fastq \
# $1 \
# $2 \
# 2>>$log 1>&2

## for miseq 2X300bp, 


${tools_path}/Python-2.7.10/python \
$cutadapt \
-e 0.12 \
--overlap 4 \
-n 3 \
-m 45 \
-u +20 \
-u -20 \
-U +20 \
-U -20 \
-a $tem_seq1 \
-A $tem_seq2 \
-a $truseq_0_20 \
-A $truseq_uni_res_com_20 \
-o $out_prefix.1.cut.fastq \
-p $out_prefix.2.cut.fastq \
$1 \
$2

# --discard-untrimmed \

. $cmd_done

